var scoreCardStatsTimeStamp = 0;
var GameID = $('input[name="gameID"]').val();
var xhrScoreCard;
var isxhrScoreCardActive = false;


function waitForScoreCardStats()
{
  location.hash = "livefeed";

    var serverURL = '/dazzler/longpoller/';
    var currentInnings=null;
    if (mainStatsObj.Innings == null)
        {
           currentInnings=1;
        }
        else
        {
           currentInnings = mainStatsObj.Innings;
        }
 var dataToPost= {  'GameID':GameID,'pollType':'scoreCardStats','innings':currentInnings,'scoreCardStatsTimeStamp':scoreCardStatsTimeStamp};
 isxhrScoreCardActive = true;
  xhrScoreCard = $.ajax({
       type: 'post',
       url: serverURL,
       data: dataToPost,
       dataType: "json",
       async: true,
       cache: false ,
       beforesend: function() {
       
    isxhrScoreCardActive = true;
  },
       success: function(data)
       {
      // isxhrScoreCardActive = true;
          $('#tabs div:first').children().hide();
    $("#tabs div:first .loadingScreenTabContainer").html("<p style='margin-top : 0px; text-align: center; vertical-align: middle; height: 100%;'><img src="+$('#loadingImage').val()+" align='middle' alt='Loading Pic is Missing' /></p>").show();
        populateFullScoreCard(data.battingScoreCard,data.bowlingScoreCard,data.fallofwickets);
         scoreCardStatsTimeStamp = data.newTimeStamp;
         waitForScoreCardStats();


       },
            error: function(XMLHttpRequest, textStatus, errorThrown){
               
                $("#pageheader").html("Full Score Card Long Poller switched off.");
                 isxhrScoreCardActive = false;
//                setTimeout(
//
//               'waitForScoreCardStats()', /* Try again after.. */
//                    "5000"); /* milliseconds (5 seconds) */
            }

    });

}

function populateFullScoreCard(battingScoreCard,bowlingScoreCard,fallofwickets)
{


    $("#fullBattingScoreCardContainer").html(battingScoreCard);
    $("#fullBowlingScoreCardContainer").html(bowlingScoreCard);
    $("#fallOfWicketsContainer").html(fallofwickets);
    $('#tabs div:first').children().show('blind',{},1000);
    $("#tabs div:first .loadingScreenTabContainer").html("").hide();

}

